package com.member.web.controller.shop;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.member.common.core.domain.entity.SysUser;
import com.member.common.core.domain.model.LoginUser;
import com.member.common.utils.bean.BeanUtils;
import com.member.shop.domain.SysBizGoodsEvaluateOut;
import com.member.shop.domain.SysBizGoodsSku;
import com.member.shop.domain.SysBizUser;
import com.member.shop.dto.EvaluateTemplateDto;
import org.springframework.security.access.prepost.PreAuthorize;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.enums.BusinessType;
import com.member.shop.domain.SysBizGoodsEvaluate;
import com.member.shop.service.ISysBizGoodsEvaluateService;
import com.member.common.utils.poi.ExcelUtil;
import com.member.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【商品评价】控制器
 *
 * @author wangxin
 * @version 1.0
 * @date 2024-01-08
 **/
@RestController
@RequestMapping("/shop/evaluate")
public class SysBizGoodsEvaluateController extends BaseController {
    @Resource
    private ISysBizGoodsEvaluateService sysBizGoodsEvaluateService;

    /**
     * 查询商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizGoodsEvaluate sysBizGoodsEvaluate) {
        startPage();

        List<SysBizGoodsEvaluate> list = sysBizGoodsEvaluateService.selectSysBizGoodsEvaluateList(sysBizGoodsEvaluate);
        return getDataTable(list);
    }

    /**
     * 查询商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:list')")
    @GetMapping("/evaluateList")
    public TableDataInfo evaluateList(SysBizGoodsEvaluate sysBizGoodsEvaluate) {
        startPage();
        List<SysBizGoodsEvaluate> list = sysBizGoodsEvaluateService.selectSysBizGoodsEvaluateList(sysBizGoodsEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:leadingOut')")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/leadingOut")
    public void export(HttpServletResponse response, SysBizGoodsEvaluate sysBizGoodsEvaluate) {
        List<SysBizGoodsEvaluateOut> list = sysBizGoodsEvaluateService.selectSysBizGoodsEvaluateListOut(sysBizGoodsEvaluate);
        ExcelUtil<SysBizGoodsEvaluateOut> util = new ExcelUtil<SysBizGoodsEvaluateOut>(SysBizGoodsEvaluateOut. class);
        util.exportExcel(response, list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizGoodsEvaluateService.selectSysBizGoodsEvaluateById(id));
    }

    /**
     * 新增商品评价
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:add')")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizGoodsEvaluate sysBizGoodsEvaluate) {
        return toAjax(sysBizGoodsEvaluateService.insertSysBizGoodsEvaluate(sysBizGoodsEvaluate));
    }

    /**
     * 修改商品评价
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:edit')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizGoodsEvaluate sysBizGoodsEvaluate) {
        return toAjax(sysBizGoodsEvaluateService.updateSysBizGoodsEvaluate(sysBizGoodsEvaluate));
    }

    /**
     * 删除商品评价
     */
    @PreAuthorize("@ss.hasPermi('shop:evaluate:remove')")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(sysBizGoodsEvaluateService.deleteSysBizGoodsEvaluateById(id));
    }
    /**
     * 模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<EvaluateTemplateDto> util = new ExcelUtil<EvaluateTemplateDto>(EvaluateTemplateDto.class);
        util.importTemplateExcel(response, "评价模板");
    }

    /**
     * 商品评价导入
     */
    @Log(title = "商品评价导入", businessType = BusinessType.IMPORT)
    @PostMapping("/registerImportData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<EvaluateTemplateDto> util = new ExcelUtil<EvaluateTemplateDto>(EvaluateTemplateDto.class);
        List<EvaluateTemplateDto> evaluateTemplateDto = util.importExcel(file.getInputStream());
        LoginUser loginUser = getLoginUser();
        String operName = loginUser.getUsername();
        int message = sysBizGoodsEvaluateService.importData(evaluateTemplateDto, updateSupport, operName);
        return  AjaxResult.success(message);
    }
}
